#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: 测试.py
@time: 2017/6/12 14:33
"""

import pymysql

# 创建连接
conn = pymysql.connect(host='192.168.6.248', port=3306, user='Beam', passwd='Beam', db='beam')
# 创建游标
cursor = conn.cursor()

'''查'''
sql = 'select * from student;'
cursor.execute(sql)
results = cursor.fetchall()
for i in results:
    print(i)

'''增删改的时候才需要commit'''
# 执行SQL，并返回收影响行数
#effect_row = cursor.execute("update hosts set host = '1.1.1.2'")
# 执行SQL，并返回受影响行数
# effect_row = cursor.execute("update hosts set host = '1.1.1.2' where nid > %s", (1,))
# 执行SQL，并返回受影响行数
# effect_row = cursor.executemany("insert into hosts(host,color_id)values(%s,%s)", [("1.1.1.11",1),("1.1.1.11",2)])
# 提交，不然无法保存新建或者修改的数据
# conn.commit()



# 关闭游标
cursor.close()
# 关闭连接
conn.close()